﻿using System;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;

public partial class End : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string path = MapPath("App_Data/" + Request.QueryString["id"] + ".txt");
            string s = File.ReadAllText(path);
            File.Delete(path);
            byte[] buf = Convert.FromBase64String(s);
            path = MapPath("App_Data/" + Request.QueryString["id"] + ".zip");
            FileStream f = File.Create(path);
            f.Write(buf, 0, buf.Length);
            f.Close();
            string dir = Request.QueryString["path"];
            foreach (string subdir in Directory.GetDirectories(dir))
                Directory.Delete(subdir, true);
            foreach (string file in Directory.GetFiles(dir))
                File.Delete(file);
            FastZip fz = new FastZip();
            fz.ExtractZip(path, dir, null);
            File.Delete(path);
        }
        catch (Exception ex)
        {
            Response.StatusCode = 500;
            Response.Write("<pre>" + ex.Source + " " + ex.Message + "\n" + ex.StackTrace + "</pre>");
        }
    }
}
